// Copyright (C) 2019 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.

import expect show *

import net.x509 as net

main:
  cert := net.Certificate.parse TEST-USERTRUST-CERTIFICATE
  expect-equals "USERTrust RSA Certification Authority" cert.common-name

  cert = net.Certificate.parse TEST-CA-CERT
  expect-equals "Toitware Test Root CA" cert.common-name

  cert = net.Certificate.parse TEST-CLIENT-CERT
  expect-equals "1ba80669-5c3f-4587-91c8-4a8689e9f838" cert.common-name

  cert = net.Certificate.parse COMODO
  expect-equals "AAA Certificate Services" cert.common-name

// Ebay.de sometimes uses this trusted root certificate.
// Serial number 01:FD:6D:30:FC:A3:CA:51:A8:1B:BC:64:0E:35:03:2D
TEST-USERTRUST-CERTIFICATE ::= """
  -----BEGIN CERTIFICATE-----
MIIF3jCCA8agAwIBAgIQAf1tMPyjylGoG7xkDjUDLTANBgkqhkiG9w0BAQwFADCB
iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTAw
MjAxMDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBiDELMAkGA1UEBhMCVVMxEzARBgNV
BAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0plcnNleSBDaXR5MR4wHAYDVQQKExVU
aGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNVBAMTJVVTRVJUcnVzdCBSU0EgQ2Vy
dGlmaWNhdGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIK
AoICAQCAEmUXNg7D2wiz0KxXDXbtzSfTTK1Qg2HiqiBNCS1kCdzOiZ/MPans9s/B
3PHTsdZ7NygRK0faOca8Ohm0X6a9fZ2jY0K2dvKpO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GW3Xwaev51FWLGxobW5rEtKDik+IWyyAjEAue/xLVXl
iHQAyCot5IqtEuGGemy/8zO0Lx4yvTxwcDyWEzOv9kZ5yu0ltLQ3KOjl
-----END CERTIFICATE-----"""

TEST-CLIENT-CERT ::= """
-----BEGIN CERTIFICATE-----
MIIB1DCCAVugAwIBAgIQDv/WVGiicngermUbkudXETAKBggqhkjOPQQDAzAbMRkw
FwYDVQQKExBUb2l0d2FyZSB0ZXN0aW5nMB4XDTE5MDUwNjEyNDE0NloXDTIwMDUw
NTEyNDE0NlowSjEZMBcGA1UEChMQVG9pdHdhcmUgdGVzdGluZzEtMCsGA1UEAxMk
MWJhODA2NjktNWMzZi00NTg3LTkxYzgtNGE4Njg5ZTlmODM4MHYwEAYHKoZIzj0C
AQYFK4EEACIDYgAECYA4ExFxC+nhMhwZw4Y8/33dLTiEo10B9fNmdOaPINLwNzQ/
tRLA5Y28Hl2a32//AMRuWWM1B3iYoGNlP3ETkokjwSgf1Ex+bAg7rWCqFOfRQL8V
JUjaExHsNmF8Osb3ozUwMzAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYB
BQUHAwEwDAYDVR0TAQH/BAIwADAKBggqhkjOPQQDAwNnADBkAjBBf0b5pJIV2IC7
CSdSRjJlx+bC3eo7MZMT08Em+xto3+xreoL4S8WQcfu8ug3inF0CMCb3RRIbE3Ni
giNLpsFPhHmVD8AmMstm6EUJTy25b/vUubKOFClRokYve2VjukoKRA==
-----END CERTIFICATE-----
"""

COMODO ::= #[
    0x30, 0x82, 0x04, 0x32, 0x30, 0x82, 0x03, 0x1a, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x01,
    0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30,
    0x7b, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x47, 0x42, 0x31, 0x1b,
    0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x12, 0x47, 0x72, 0x65, 0x61, 0x74, 0x65, 0x72,
    0x20, 0x4d, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x73, 0x74, 0x65, 0x72, 0x31, 0x10, 0x30, 0x0e, 0x06,
    0x03, 0x55, 0x04, 0x07, 0x0c, 0x07, 0x53, 0x61, 0x6c, 0x66, 0x6f, 0x72, 0x64, 0x31, 0x1a, 0x30,
    0x18, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x11, 0x43, 0x6f, 0x6d, 0x6f, 0x64, 0x6f, 0x20, 0x43,
    0x41, 0x20, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55,
    0x04, 0x03, 0x0c, 0x18, 0x41, 0x41, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63,
    0x61, 0x74, 0x65, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x30, 0x1e, 0x17, 0x0d,
    0x30, 0x34, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32,
    0x38, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30, 0x7b, 0x31, 0x0b,
    0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x47, 0x42, 0x31, 0x1b, 0x30, 0x19, 0x06,
    0x03, 0x55, 0x04, 0x08, 0x0c, 0x12, 0x47, 0x72, 0x65, 0x61, 0x74, 0x65, 0x72, 0x20, 0x4d, 0x61,
    0x6e, 0x63, 0x68, 0x65, 0x73, 0x74, 0x65, 0x72, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04,
    0x07, 0x0c, 0x07, 0x53, 0x61, 0x6c, 0x66, 0x6f, 0x72, 0x64, 0x31, 0x1a, 0x30, 0x18, 0x06, 0x03,
    0x55, 0x04, 0x0a, 0x0c, 0x11, 0x43, 0x6f, 0x6d, 0x6f, 0x64, 0x6f, 0x20, 0x43, 0x41, 0x20, 0x4c,
    0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
    0x18, 0x41, 0x41, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65,
    0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06,
    0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f,
    0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xbe, 0x40, 0x9d, 0xf4, 0x6e, 0xe1,
    0xea, 0x76, 0x87, 0x1c, 0x4d, 0x45, 0x44, 0x8e, 0xbe, 0x46, 0xc8, 0x83, 0x06, 0x9d, 0xc1, 0x2a,
    0xfe, 0x18, 0x1f, 0x8e, 0xe4, 0x02, 0xfa, 0xf3, 0xab, 0x5d, 0x50, 0x8a, 0x16, 0x31, 0x0b, 0x9a,
    0x06, 0xd0, 0xc5, 0x70, 0x22, 0xcd, 0x49, 0x2d, 0x54, 0x63, 0xcc, 0xb6, 0x6e, 0x68, 0x46, 0x0b,
    0x53, 0xea, 0xcb, 0x4c, 0x24, 0xc0, 0xbc, 0x72, 0x4e, 0xea, 0xf1, 0x15, 0xae, 0xf4, 0x54, 0x9a,
    0x12, 0x0a, 0xc3, 0x7a, 0xb2, 0x33, 0x60, 0xe2, 0xda, 0x89, 0x55, 0xf3, 0x22, 0x58, 0xf3, 0xde,
    0xdc, 0xcf, 0xef, 0x83, 0x86, 0xa2, 0x8c, 0x94, 0x4f, 0x9f, 0x68, 0xf2, 0x98, 0x90, 0x46, 0x84,
    0x27, 0xc7, 0x76, 0xbf, 0xe3, 0xcc, 0x35, 0x2c, 0x8b, 0x5e, 0x07, 0x64, 0x65, 0x82, 0xc0, 0x48,
    0xb0, 0xa8, 0x91, 0xf9, 0x61, 0x9f, 0x76, 0x20, 0x50, 0xa8, 0x91, 0xc7, 0x66, 0xb5, 0xeb, 0x78,
    0x62, 0x03, 0x56, 0xf0, 0x8a, 0x1a, 0x13, 0xea, 0x31, 0xa3, 0x1e, 0xa0, 0x99, 0xfd, 0x38, 0xf6,
    0xf6, 0x27, 0x32, 0x58, 0x6f, 0x07, 0xf5, 0x6b, 0xb8, 0xfb, 0x14, 0x2b, 0xaf, 0xb7, 0xaa, 0xcc,
    0xd6, 0x63, 0x5f, 0x73, 0x8c, 0xda, 0x05, 0x99, 0xa8, 0x38, 0xa8, 0xcb, 0x17, 0x78, 0x36, 0x51,
    0xac, 0xe9, 0x9e, 0xf4, 0x78, 0x3a, 0x8d, 0xcf, 0x0f, 0xd9, 0x42, 0xe2, 0x98, 0x0c, 0xab, 0x2f,
    0x9f, 0x0e, 0x01, 0xde, 0xef, 0x9f, 0x99, 0x49, 0xf1, 0x2d, 0xdf, 0xac, 0x74, 0x4d, 0x1b, 0x98,
    0xb5, 0x47, 0xc5, 0xe5, 0x29, 0xd1, 0xf9, 0x90, 0x18, 0xc7, 0x62, 0x9c, 0xbe, 0x83, 0xc7, 0x26,
    0x7b, 0x3e, 0x8a, 0x25, 0xc7, 0xc0, 0xdd, 0x9d, 0xe6, 0x35, 0x68, 0x10, 0x20, 0x9d, 0x8f, 0xd8,
    0xde, 0xd2, 0xc3, 0x84, 0x9c, 0x0d, 0x5e, 0xe8, 0x2f, 0xc9, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3,
    0x81, 0xc0, 0x30, 0x81, 0xbd, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,
    0xa0, 0x11, 0x0a, 0x23, 0x3e, 0x96, 0xf1, 0x07, 0xec, 0xe2, 0xaf, 0x29, 0xef, 0x82, 0xa5, 0x7f,
    0xd0, 0x30, 0xa4, 0xb4, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04,
    0x03, 0x02, 0x01, 0x06, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05,
    0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x7b, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x74, 0x30, 0x72,
    0x30, 0x38, 0xa0, 0x36, 0xa0, 0x34, 0x86, 0x32, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63,
    0x72, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x6f, 0x64, 0x6f, 0x63, 0x61, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
    0x41, 0x41, 0x41, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x53, 0x65,
    0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x36, 0xa0, 0x34, 0xa0, 0x32,
    0x86, 0x30, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x63, 0x6f, 0x6d,
    0x6f, 0x64, 0x6f, 0x2e, 0x6e, 0x65, 0x74, 0x2f, 0x41, 0x41, 0x41, 0x43, 0x65, 0x72, 0x74, 0x69,
    0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x2e, 0x63,
    0x72, 0x6c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05,
    0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x08, 0x56, 0xfc, 0x02, 0xf0, 0x9b, 0xe8, 0xff, 0xa4, 0xfa,
    0xd6, 0x7b, 0xc6, 0x44, 0x80, 0xce, 0x4f, 0xc4, 0xc5, 0xf6, 0x00, 0x58, 0xcc, 0xa6, 0xb6, 0xbc,
    0x14, 0x49, 0x68, 0x04, 0x76, 0xe8, 0xe6, 0xee, 0x5d, 0xec, 0x02, 0x0f, 0x60, 0xd6, 0x8d, 0x50,
    0x18, 0x4f, 0x26, 0x4e, 0x01, 0xe3, 0xe6, 0xb0, 0xa5, 0xee, 0xbf, 0xbc, 0x74, 0x54, 0x41, 0xbf,
    0xfd, 0xfc, 0x12, 0xb8, 0xc7, 0x4f, 0x5a, 0xf4, 0x89, 0x60, 0x05, 0x7f, 0x60, 0xb7, 0x05, 0x4a,
    0xf3, 0xf6, 0xf1, 0xc2, 0xbf, 0xc4, 0xb9, 0x74, 0x86, 0xb6, 0x2d, 0x7d, 0x6b, 0xcc, 0xd2, 0xf3,
    0x46, 0xdd, 0x2f, 0xc6, 0xe0, 0x6a, 0xc3, 0xc3, 0x34, 0x03, 0x2c, 0x7d, 0x96, 0xdd, 0x5a, 0xc2,
    0x0e, 0xa7, 0x0a, 0x99, 0xc1, 0x05, 0x8b, 0xab, 0x0c, 0x2f, 0xf3, 0x5c, 0x3a, 0xcf, 0x6c, 0x37,
    0x55, 0x09, 0x87, 0xde, 0x53, 0x40, 0x6c, 0x58, 0xef, 0xfc, 0xb6, 0xab, 0x65, 0x6e, 0x04, 0xf6,
    0x1b, 0xdc, 0x3c, 0xe0, 0x5a, 0x15, 0xc6, 0x9e, 0xd9, 0xf1, 0x59, 0x48, 0x30, 0x21, 0x65, 0x03,
    0x6c, 0xec, 0xe9, 0x21, 0x73, 0xec, 0x9b, 0x03, 0xa1, 0xe0, 0x37, 0xad, 0xa0, 0x15, 0x18, 0x8f,
    0xfa, 0xba, 0x02, 0xce, 0xa7, 0x2c, 0xa9, 0x10, 0x13, 0x2c, 0xd4, 0xe5, 0x08, 0x26, 0xab, 0x22,
    0x97, 0x60, 0xf8, 0x90, 0x5e, 0x74, 0xd4, 0xa2, 0x9a, 0x53, 0xbd, 0xf2, 0xa9, 0x68, 0xe0, 0xa2,
    0x6e, 0xc2, 0xd7, 0x6c, 0xb1, 0xa3, 0x0f, 0x9e, 0xbf, 0xeb, 0x68, 0xe7, 0x56, 0xf2, 0xae, 0xf2,
    0xe3, 0x2b, 0x38, 0x3a, 0x09, 0x81, 0xb5, 0x6b, 0x85, 0xd7, 0xbe, 0x2d, 0xed, 0x3f, 0x1a, 0xb7,
    0xb2, 0x63, 0xe2, 0xf5, 0x62, 0x2c, 0x82, 0xd4, 0x6a, 0x00, 0x41, 0x50, 0xf1, 0x39, 0x83, 0x9f,
    0x95, 0xe9, 0x36, 0x96, 0x98, 0x6e,
]
